package com.glls.java2212.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @date 2022/10/10
 * @desc  拦截器   一个临时的  跨域解决方案
 */
public class MyInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String origin = request.getHeader("Origin");

        // 允许的跨域
        response.setHeader("Access-Control-Allow-Origin",origin);
        // 允许携带Cookie
        response.setHeader("Access-Control-Allow-Credentials","true");


        return true;

    }
}
